package cn.kgc.pojo;

import cn.kgc.validate.userInsert;
import cn.kgc.validate.userLogin;
import com.alibaba.fastjson.annotation.JSONField;
import com.sun.istack.internal.NotNull;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

import javax.print.attribute.standard.MediaSize;
import javax.validation.constraints.*;
import java.util.Date;




@SuppressWarnings("all")
public class User {
    private Long id;

    //@NotNull == ''
    @NotEmpty(message = "{user.notEmpty}",groups = {userInsert.class})
    private String usercode;

    @Length(min = 3,max = 5,message = "{user.username.length}", groups = {userInsert.class,userLogin.class})
    private String username;

    /*@Pattern(regexp = "\\w+@163.com")*/
    @Length(min = 2,max = 4,message = "{user.userpassword.length}",groups = {userInsert.class,userLogin.class})
    private String userpassword;


    private Integer gender;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    /*@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)*/
    @Past(message = "{user.birthday.past}",groups = {userInsert.class})
    /*@Future*/
    /*@JSONField(format = "yyyy-MM-dd")*/
    private Date birthday;

    @NotEmpty(message = "{user.notEmpty}",groups = {userInsert.class})
    @Pattern(regexp = "\\d*",message = "{user.birthday.past}")
    private String phone;

    @NotEmpty(message = "{user.notEmpty}",groups = {userInsert.class})
    private String address;


    private Long userrole;

    private String rolename;

    public String getRolename() {
        return rolename;
    }

    public void setRolename(String rolename) {
        this.rolename = rolename;
    }

    @Min(value = 0,message = "{user.age.min}",groups = {userInsert.class})
    @Max(value = 100,message = "{user.age.max}",groups = {userInsert.class})
    private int age;
    public int getAge(){
        return new Date().getYear()-this.birthday.getYear();
    }

    private Long createdby;

    private Date creationdate;

    private Long modifyby;

    private Date modifydate;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsercode() {
        return usercode;
    }

    public void setUsercode(String usercode) {
        this.usercode = usercode == null ? null : usercode.trim();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getUserpassword() {
        return userpassword;
    }

    public void setUserpassword(String userpassword) {
        this.userpassword = userpassword == null ? null : userpassword.trim();
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address ;
    }

    public Long getUserrole() {
        return userrole;
    }

    public void setUserrole(Long userrole) {
        this.userrole = userrole;
    }

    public Long getCreatedby() {
        return createdby;
    }

    public void setCreatedby(Long createdby) {
        this.createdby = createdby;
    }

    public Date getCreationdate() {
        return creationdate;
    }

    public void setCreationdate(Date creationdate) {
        this.creationdate = creationdate;
    }

    public Long getModifyby() {
        return modifyby;
    }

    public void setModifyby(Long modifyby) {
        this.modifyby = modifyby;
    }

    public Date getModifydate() {
        return modifydate;
    }

    public void setModifydate(Date modifydate) {
        this.modifydate = modifydate;
    }


    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", usercode='" + usercode + '\'' +
                ", username='" + username + '\'' +
                ", userpassword='" + userpassword + '\'' +
                ", gender=" + gender +
                ", birthday=" + birthday +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                ", userrole=" + userrole +
                ", rolename='" + rolename + '\'' +
                ", age=" + age +
                ", createdby=" + createdby +
                ", creationdate=" + creationdate +
                ", modifyby=" + modifyby +
                ", modifydate=" + modifydate +
                '}';
    }
}